<%--
  Created by IntelliJ IDEA.
  User: dell、
  Date: 2017/5/10
  Time: 13:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <meta charset="utf-8"/>
    <title>待催收任务</title>
    <link href="static/mycss/bootstrap.min.css" rel="stylesheet" />
    <script src='static/js/jquery-2.1.3.min.js'></script>
    <script src='static/js/commonJs.js${getTime}'></script>
    <script type="text/javascript" src="static/js/layer.js"></script>
    <script type="text/javascript"  src="static/layui/layui.js"></script>
    <script type="text/ecmascript" src="static/js/jqgrid/grid.locale-en.js"></script>
    <script type="text/ecmascript" src="static/js/jqgrid/jquery.jqGrid.min.js"></script>
    <link rel="stylesheet" type="text/css" media="screen" href="static/js/jqgrid/ui.jqgrid-bootstrap.css" />
    <script type="text/ecmascript" src="static/js/jqgrid/jqGridCommon.js${getTime}"></script>
    <script type="text/javascript" src="static/js/jquery.tips.js"></script>
    <script type="text/javascript" src="static/js/jquery.serializejson.min.js"></script>
    <link rel="stylesheet" href="static/layui/css/layui.css" media="all">
    <style>
        #toGoPage {
            height: 30px;
        }
    </style>
    <link href="static/css/bootstrap.min.css" rel="stylesheet"/>
    <script type="text/javascript">
        $(function(){
        	//enter键 触发 查询
			enterEvent();
			//下拉框change 触发 查询
			selectChangeEvent();
			// 查询
			searchEvent();
			//清空
			resetBtnEvent();
			//初始化时间控件
			initDateEvent();
			//批量分派
			piliangfenpai();
			//excel导出
			outExcel();
			//委外分派
            weiwaifenpai();
            //平均分派
			pingjunfenppai();
        });

        /**
         * 查询
         * */
        function searchEvent(){
			$("#refreshList").click(function(){
				refreshGridListEvent();
			});
        }

        /**
         * excel导出
         * */
        function outExcel(){
			$(".exportExcelBtn").click(function(){
				if(formExistNotNUll()){
					var index = layer.load();
					<%--window.location.href = '<%=basePath%>loanTaskToBe/excel.do?' + $("#toBeForm").serialize();--%>
					$.getExcel('<%=basePath%>loanTaskToBe/excel2.do?' + $("#toBeForm").serialize());
					layer.close(index);
				}else {
					layer.msg("请先查询出需要的数据再导出Excel！", {
						icon: 5,
						time: 2500
					});
				}
			});
        }

        /**
         * 批量分派
         * */
        function piliangfenpai() {
			$("#fenpai").click(function(){
				var ids = getSelectCallLoanNid();
				if (ids.length == 0) {
					layer.msg("请勾选要分派的数据！", {
						icon: 5,
						time: 2000
					});
					return;
				}else {
					openDialog({
						title: "批量分派操作",
						url: "taskdetails/plliangfenpailist?fpId=" + ids + "&flag=1"
					});
				}
			});
		}

		/**
         * 委外分派
         * */
		function weiwaifenpai(){
			$("#outPush").click(function () {
				var ids = getSelectCallLoanNid();
				if (ids.length == 0) {
					layer.msg("请勾选要委外的数据！", {
						icon: 5,
						time: 2000
					});
					return;
				} else {
					layer.confirm('是否确认批量委外?', {
						btn: ['确定', '取消'] //按钮
					}, function () {
						$.ajax({
							type: "post",
							url: "loanTaskToBe/toWeiwai.do?ids=" + ids,
							success: function (data) {
								if (data == 'success') {
									layer.alert("委外成功");
									refreshGridListEvent();
								} else {
									layer.alert("委外失败")
								}
							}
						})
					});
				}
			});
        }

        /**
         * 平均分派
         * */
        function pingjunfenppai() {
			//平均分派
			$("#autoFenpai").click(function () {
				layer.open({
                    title:"平均分派",
					type: 2,
					content: 'taskdetails/avgDispatchedPage/' + $("#pageTotal").val(),
					fixed: false,
					area: ['550px', '710px'],
					offset: '15px',
					end: function () {
						refreshGridListEvent();
					}
				});
			});
		}

		/**
         * 刷新
		 */
		function refreshGridListEvent(){
			$("#toBeList").refreshGridList($("#toBeForm").serializeJSON());
        }

        /**
         * 清空
         * */
        function resetBtnEvent(){
			$("#resetBtn").click(function(){
				$("#toBeForm").get(0).reset();
				refreshGridListEvent();
			});
        }
		/**
         * enter事件触发查询
		 */
		function enterEvent(){
			$(document).keyup(function(event) {
				if (event.keyCode == 13) {
					refreshGridListEvent();
				}
			});
        }

		/**
         *下拉框值改变 自动触发 查询
		 */
		function selectChangeEvent(){
			$("select").change(function(){
				refreshGridListEvent();
			});
        }

		/**
		 * 初始化日期控件
		 * */
        function initDateEvent(){
			layui.use('laydate', function() {
				var laydate = layui.laydate;
				laydate.render({elem: '#minCreateTime',done:function(){
					refreshGridListEvent();
				}});
				laydate.render({elem: '#maxCreateTime',done:function(){
					refreshGridListEvent();
				}});
				//回收时间
                laydate.render({elem: '#minWithdrawTime',type: 'datetime'});
                laydate.render({elem: '#maxWithdrawTime',type: 'datetime'});
			});
        }

        /**
        * 获取批量分派 所 获取的 催收编号
        * */
        function getSelectCallLoanNid(){
        	var ids = [];
        	var selectData = $("#toBeList").getSelectRow().getSelecRowtData();
            $.each(selectData,function(i,n){
				ids.push($(n.call_loan_nid).html());
            });
            return ids;
        }

		/* 打开窗口 */
		function openDialog(options) {
			var defaultOptions = {
				title: "",
				url: "",
				callBack: function () {
					refreshGridListEvent();
				}
			};
			options = $.extend(defaultOptions, options);
			layer.open({
				title: options.title,
				fixed: false,
				type: 2,
				content: options.url,
				area: ['800px', '600px'],
				end: options.callBack
			});
		}

		/**
         * 表单 元素 是否存在空值
		 * @returns {boolean}
		 */
		function formExistNotNUll() {
			//表单存在非空值
			var result = false;
			$.each($(".layui-input-inline"),function(i,n){
				var tagObj = $(n).children().first();
				if(tagObj.val()) {
					//表单存在空值
					result = true;
					return false;
				}
			});
			return result;
		}
    </script>
</head>
<body>
    <div class="layui-container" style="width: 100%">
        <div class="layui-row" style="width:99%;border: 1px solid gray;margin-bottom: 10px;">
            <form id="toBeForm" class="layui-form layui-form-pane" style="margin: 10px 10px;" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="background-color: #E8E8E8">借款产品</label>
                        <div class="layui-input-inline">
                            <select id="productSource" name="productSource"  style="display: block;height: 38px;width: 190px;">
                                <option value="" psId="">不限</option>
                                <option value="2" psId="182180001">今日现金</option>
                                <option value="6" psId="186180001">卡贷</option>
                                <option value="39" psId="1839180001">融360</option>
                                <option value="41" psId="1841180001">消费分期</option>
                                <option value="43" psId="1843180001">游戏贷</option>
                                <option value="8" psId="188180001">教育分期</option>
                                <option value="45" psId="1839180002">游戏贷融360</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="background-color: #E8E8E8">入案时间</label>
                        <div class="layui-input-inline" style="width: 88px;">
                            <input type="text" id="minCreateTime" name="minCreateTime" class="layui-input"
                                   style="height: 38px;">
                        </div>
                        <div class="layui-form-mid">至</div>
                        <div class="layui-input-inline" style="width: 88px;">
                            <input type="text" id="maxCreateTime" name="maxCreateTime" class="layui-input"
                                   style="height: 38px;">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="background-color: #E8E8E8">回收时间</label>
                        <div class="layui-input-inline" style="width: 88px;width: 200px;">
                            <input type="text" id="minWithdrawTime" name="minWithdrawTime" class="layui-input"
                                   style="height: 38px;">
                        </div>
                        <div class="layui-form-mid">至</div>
                        <div class="layui-input-inline" style="width: 88px;width: 200px;">
                            <input type="text" id="maxWithdrawTime" name="maxWithdrawTime" class="layui-input"
                                   style="height: 38px;">
                        </div>
                    </div>

                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="background-color: #E8E8E8">逾期阶段</label>
                        <div class="layui-input-inline">
                            <select id="overduePhase" name="overduePhase" style="display: block;height: 38px;width: 190px;">
                                <option value="">不限</option>
                                <c:forEach items="${overduePhase}" var="var">
                                    <option value="${var.key}">${var.value}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="background-color: #E8E8E8">未还罚息</label>
                        <div class="layui-input-inline" style="width: 88px;">
                            <input type="text" name="minOverdueFee" class="layui-input" style="height: 38px;">
                        </div>
                        <div class="layui-form-mid">至</div>
                        <div class="layui-input-inline" style="width: 88px;">
                            <input type="text" name="maxOverdueFee" class="layui-input" style="height: 38px;">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="background-color: #E8E8E8">逾期天数</label>
                        <div class="layui-input-inline" style="width: 88px;">
                            <input type="text" name="overdueDateNumMin" class="layui-input" style="height: 38px;">
                        </div>
                        <div class="layui-form-mid">至</div>
                        <div class="layui-input-inline" style="width: 88px;">
                            <input type="text" name="overdueDateNumMax" class="layui-input" style="height: 38px;">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="background-color: #E8E8E8">待还金额</label>
                        <div class="layui-input-inline" style="width: 88px;">
                            <input type="text" name="minOverdueAmount" class="layui-input" style="height: 38px;">
                        </div>
                        <div class="layui-form-mid">至</div>
                        <div class="layui-input-inline" style="width: 88px;">
                            <input type="text" name="maxOverdueAmount" class="layui-input" style="height: 38px;">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="background-color: #E8E8E8">自定义项</label>
                    <div class="layui-input-inline">
                        <input type="text" name="telephone" style="display: block;height: 38px;width: 190px;"
                               placeholder="手机号（本人）" class="layui-input">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="idCard" style="display: block;height: 38px;width: 190px;"
                               placeholder="借款人身份证" class="layui-input">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="realName" style="display: block;height: 38px;width: 190px;"
                               placeholder="借款人姓名" class="layui-input">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="borrowNid" style="display: block;height: 38px;width: 190px;"
                               placeholder="借款编号" class="layui-input">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="callLoanNid" style="display: block;height: 38px;width: 190px;"
                               placeholder="催收编号" class="layui-input">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="province" style="display: block;height: 38px;width: 190px;"
                               placeholder="客户户籍" class="layui-input">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="orderNum" style="display: block;height: 38px;width: 190px;"
                               placeholder="还款订单号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-btn layui-btn-normal" id="refreshList">查询</label>
                    <button id="resetBtn" type="button" class="layui-btn layui-btn-normal" style="margin-top: -5px;">清空</button>
                    <c:if test="${QX3==1}">
                        <label class="layui-btn layui-btn-normal" id="fenpai">批量分派</label>
                    </c:if>
                    <c:if test="${QX1==1}">
                        <label class="layui-btn layui-btn-normal exportExcelBtn">导出Excel</label>
                    </c:if>
                    <c:if test="${QX4==1}">
                        <label class="layui-btn layui-btn-normal" id="outPush">批量委外</label>
                    </c:if>
                    <c:if test="${QX3==1}">
                        <label class="layui-btn layui-btn-normal" id="autoFenpai">平均分派</label>
                    </c:if>
                </div>
            </form>
        </div>
		<div class="layui-row" id="toBeList" style="height: 1%;position:relative;top: 8px;">
			<table id="loanToBe"></table>
			<div id="loanToBePage"></div>
		</div>
    </div>
<script>
	$(function(){
		$(top.hangge());
		$("#toBeList").gridList({
			url: "loanTaskToBe/list/data",
			colModel: [
				setColumn("催收编号","call_loan_nid",{width:55,formatter:
                    function(cellvalue, options, rowObject){
					return '<a href="javascript:void(0)" onclick="$.tiaozhuan(this,\''+cellvalue+'\',\''
                        + rowObject["user_id"]+ '\',\''+ rowObject["repayment_id"]+ '\',\''+ rowObject["real_name"]+ '\',\''+"dai"+'\')" style="color: blue;">'
                        + cellvalue + '</a>';

					    // return '<a href="cuijimanage/toDescPage.do?callLoanNid='
                         //    + cellvalue + '&userId='+ rowObject["user_id"]+ '&repaymentId='+ rowObject["repayment_id"]
                         //    + '" ' +'style="color: blue;">' + cellvalue + '</a>';
                    }
				}),
				setColumn("借款人姓名","real_name",{width:45}),
				setColumn("借款产品名称","product_name",{width:55}),
				setColumn("逾期期数","period",{width:45,formatter:
					function(cellvalue, options, rowObject){
						return cellvalue + "/" + rowObject["period_total"];
					}
				}),
				setColumn("待还金额","overdue_amount",{width:55,sortable: true,formatter:
					function(cellvalue, options, rowObject){
						$("#jqgh_loanToBe_" +  options.colModel.name).children().show();
						return cellvalue;
					}
				}),
				setColumn("逾期阶段","overdue_stage",{width:45}),
				setColumn("逾期天数","overdue_date",{width:55,sortable: true,formatter:
					function(cellvalue, options, rowObject){
						$("#jqgh_loanToBe_" +  options.colModel.name).children().show();
						return cellvalue;
					}
				}),
				setColumn("入案时间","create_time",{width:75,sortable: false,formatter:
					function(cellvalue, options, rowObject){
						var add0 = function(m){return m<10?'0'+m:m };
						var unixTimestamp = new Date(cellvalue);
						Date.prototype.toLocaleString = function() {
							return this.getFullYear() + "-" + add0(this.getMonth() + 1) + "-" + add0(this.getDate())
								+ " " + add0(this.getHours()) + ":" + add0(this.getMinutes())
								+ ":" + add0(this.getSeconds());
						};
						return unixTimestamp.toLocaleString();
					}
				}),
                setColumn("回收时间","withdraw_time",{width:75,sortable: false,formatter:
                        function(cellvalue, options, rowObject){
                            var add0 = function(m){return m<10?'0'+m:m };
                            if (cellvalue==null){return "";}
                            var unixTimestamp = new Date(cellvalue);
                            Date.prototype.toLocaleString = function() {
                                return this.getFullYear() + "-" + add0(this.getMonth() + 1) + "-" + add0(this.getDate())
                                    + " " + add0(this.getHours()) + ":" + add0(this.getMinutes())
                                    + ":" + add0(this.getSeconds());
                            };
                            return unixTimestamp.toLocaleString();
                        }
                }),
				setColumn("还款订单号","repayment_id",{width:45})
            ],
			gridComplete:function(){
				$("#pageTotal").val($("#loanToBe").jqGrid('getGridParam','records'));
				//统计
				$.ajax({
					type: 'POST',
					url: 'count/money/status/0',
					data: $("#toBeForm").serialize(),
					success: function (data) {
						var o = $(data).text();
						if(o){
							$("#getSUM").html($(data).text());
						}
					}
				})
			}
        });
	});
</script>
<input type="hidden" id="pageTotal"/>
</body>

</html>
